<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="build空白页,gzip文件压缩," />





  <link rel="alternate" href="/atom.xml" title="OBKoro1's Blog" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.2" />






<meta name="description" content="写在前面：npm run build 是vue-cli用来打包项目的命令行，本文是关于vue-cli打包的一些常见的坑，会尽量详细的写每个步骤，大家可以一边看着文章，一边打包试试。有需要的朋友可以做一下参考，喜欢的可以点波赞，或者关注一下，希望可以帮到大家。 初始化一个项目：这里初始化一个项目，因为导致打包错误的原因多种多样，避免因为其他设置错误干扰，从头开始打包整体步骤也会更加清晰。 命令行：v">
<meta name="keywords" content="build空白页,gzip文件压缩">
<meta property="og:type" content="article">
<meta property="og:title" content="vue-cli npm run build空白页的两个坑 webpack gzip文件压缩优化打包文件">
<meta property="og:url" content="http://yoursite.com/2017/10/11/vue-cli-npm-run-build空白页的两个坑-webpack-gzip文件压缩优化打包文件/index.html">
<meta property="og:site_name" content="OBKoro1&#39;s Blog">
<meta property="og:description" content="写在前面：npm run build 是vue-cli用来打包项目的命令行，本文是关于vue-cli打包的一些常见的坑，会尽量详细的写每个步骤，大家可以一边看着文章，一边打包试试。有需要的朋友可以做一下参考，喜欢的可以点波赞，或者关注一下，希望可以帮到大家。 初始化一个项目：这里初始化一个项目，因为导致打包错误的原因多种多样，避免因为其他设置错误干扰，从头开始打包整体步骤也会更加清晰。 命令行：v">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/0324afbbfce9a0baf513417e07292c6b?raw=true">
<meta property="og:image" content="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/609c0d3e25e99744930d81e892156f0b?raw=true">
<meta property="og:image" content="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/f4afd954cdb3dc6702dbae4a8066441a?raw=true">
<meta property="og:image" content="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/bfc1ccd0318c288369a1d5d914ba16b6?raw=true">
<meta property="og:image" content="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/bafef77c3943e031154d127964508072?raw=true">
<meta property="og:image" content="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/28200b7f45b8aac0897f62124c41eec1?raw=true">
<meta property="og:image" content="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/f9c56757612f1dd5703fbf0fa09fb155?raw=true">
<meta property="og:image" content="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/1f95faabfb7463e1dce708f046960398?raw=true">
<meta property="og:image" content="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/7fd308bb2a27aba49009455266da73d3?raw=true">
<meta property="og:updated_time" content="2019-06-15T06:19:47.636Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="vue-cli npm run build空白页的两个坑 webpack gzip文件压缩优化打包文件">
<meta name="twitter:description" content="写在前面：npm run build 是vue-cli用来打包项目的命令行，本文是关于vue-cli打包的一些常见的坑，会尽量详细的写每个步骤，大家可以一边看着文章，一边打包试试。有需要的朋友可以做一下参考，喜欢的可以点波赞，或者关注一下，希望可以帮到大家。 初始化一个项目：这里初始化一个项目，因为导致打包错误的原因多种多样，避免因为其他设置错误干扰，从头开始打包整体步骤也会更加清晰。 命令行：v">
<meta name="twitter:image" content="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/0324afbbfce9a0baf513417e07292c6b?raw=true">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.2',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2017/10/11/vue-cli-npm-run-build空白页的两个坑-webpack-gzip文件压缩优化打包文件/"/>





  <title>vue-cli npm run build空白页的两个坑 webpack gzip文件压缩优化打包文件 | OBKoro1's Blog</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?64d57d0b926bbd27431daa89d2e0a76b";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">OBKoro1's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-前端算法">
          <a href="/arithmetic/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-book"></i> <br />
            
            前端算法
          </a>
        </li>
      
        
        <li class="menu-item menu-item-博客最新更新">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            博客最新更新
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-commonweal">
          <a href="/404/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br />
            
            公益404
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/10/11/vue-cli-npm-run-build空白页的两个坑-webpack-gzip文件压缩优化打包文件/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="OBKoro1">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/uploads/hand1.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="OBKoro1's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">vue-cli npm run build空白页的两个坑 webpack gzip文件压缩优化打包文件</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-10-11T23:10:07+08:00">
                2017-10-11
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/vue-cli/" itemprop="url" rel="index">
                    <span itemprop="name">vue-cli</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/2017/10/11/vue-cli-npm-run-build空白页的两个坑-webpack-gzip文件压缩优化打包文件/" class="leancloud_visitors" data-flag-title="vue-cli npm run build空白页的两个坑 webpack gzip文件压缩优化打包文件">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1,129 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  4分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="写在前面："><a href="#写在前面：" class="headerlink" title="写在前面："></a>写在前面：</h2><p>npm run build 是vue-cli用来打包项目的命令行，本文是关于vue-cli打包的一些常见的坑，会尽量详细的写每个步骤，大家可以一边看着文章，一边打包试试。有需要的朋友可以做一下参考，喜欢的可以点波赞，或者关注一下，希望可以帮到大家。</p>
<h2 id="初始化一个项目："><a href="#初始化一个项目：" class="headerlink" title="初始化一个项目："></a>初始化一个项目：</h2><p>这里初始化一个项目，因为导致打包错误的原因多种多样，避免因为其他设置错误干扰，<strong>从头开始打包整体步骤也会更加清晰</strong>。</p>
<h3 id="命令行："><a href="#命令行：" class="headerlink" title="命令行："></a>命令行：</h3><pre><code>vue init webpack build1(项目名)
//吧啦吧啦进行一波设置
//进入项目文件夹
npm install
</code></pre><p>如果还不清楚如何初始化运行一个项目，可以参考我之前写的一篇文章：<a href="https://juejin.im/post/597eee92f265da3e2e56e37c" target="_blank" rel="noopener">传送门</a>。</p>
<h2 id="开始打包踩坑"><a href="#开始打包踩坑" class="headerlink" title="开始打包踩坑"></a>开始打包踩坑</h2><h3 id="命令行：-1"><a href="#命令行：-1" class="headerlink" title="命令行："></a>命令行：</h3><pre><code>//直接打包
npm run build
</code></pre><h3 id="打包出来的文件"><a href="#打包出来的文件" class="headerlink" title="打包出来的文件"></a>打包出来的文件</h3><p><img src="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/0324afbbfce9a0baf513417e07292c6b?raw=true" alt="vue-cli项目文件打包位置"></p>
<h3 id="第一个坑：文件引用路径"><a href="#第一个坑：文件引用路径" class="headerlink" title="第一个坑：文件引用路径"></a>第一个坑：文件引用路径</h3><p>现在项目我们什么都没动，是初始化之后直接打包的状态，打开dist/index.htmnl文件整个网页都是一片空白的。</p>
<p><img src="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/609c0d3e25e99744930d81e892156f0b?raw=true" alt=""></p>
<p>打开调试，发现有一排报错说是：<code>不能加载到资源</code>，后面就发现<strong>路径的问题</strong>，仔细看上面再看上面加载的css的引用路径，这里是有问题的。</p>
<h3 id="爬坑："><a href="#爬坑：" class="headerlink" title="爬坑："></a>爬坑：</h3><p><strong>文件位置：</strong>config文件夹/index.js文件</p>
<h4 id="1-更改assetsPublicPath属性："><a href="#1-更改assetsPublicPath属性：" class="headerlink" title="1.更改assetsPublicPath属性："></a>1.更改assetsPublicPath属性：</h4><p>文件里面有两个assetsPublicPath属性，更改第一个，也就是更改build里面的assetsPublicPath属性：</p>
<pre><code>assetsPublicPath:&apos;/&apos;//false
assetsPublicPath:&apos;./&apos;//true
</code></pre><p>assetsPublicPath属性作用是指定编译发布的根目录，<strong>‘/‘指的是项目的根目录 ，’./‘指的是当前目录。</strong></p>
<h4 id="2-改好设置之后，重新打包。"><a href="#2-改好设置之后，重新打包。" class="headerlink" title="2.改好设置之后，重新打包。"></a>2.改好设置之后，重新打包。</h4><p>打开打包文件：</p>
<p><img src="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/f4afd954cdb3dc6702dbae4a8066441a?raw=true" alt="重新打开index.html"></p>
<h4 id="错误原因："><a href="#错误原因：" class="headerlink" title="错误原因："></a>错误原因：</h4><p><img src="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/bfc1ccd0318c288369a1d5d914ba16b6?raw=true" alt="dist文件夹"></p>
<p>打包出来所有的文件都会放在dist的static文件夹下面，index.html要加载文件，那么问题来了，’/‘指的是项目的根目录 ，’./‘指的是当前目录。要选哪个？当然选择原谅她了。</p>
<h3 id="第二个坑：路由history模式。"><a href="#第二个坑：路由history模式。" class="headerlink" title="第二个坑：路由history模式。"></a>第二个坑：路由history模式。</h3><p>这个坑是当你使用了路由之后，<strong>在没有后端配合的情况下就手贱打开路由history模式的时候</strong>，打包出来的文件也会是一片空白的情况，很多人踩这个坑的时候花了很多时间，网上的教程基本上都是说的第一个坑，这个坑很少有人提起。</p>
<p><img src="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/bafef77c3943e031154d127964508072?raw=true" alt="图片出自vue-router文档"></p>
<h4 id="打包之前的样子："><a href="#打包之前的样子：" class="headerlink" title="打包之前的样子："></a>打包之前的样子：</h4><p>这里我弄了个示例，因为是刚创建的项目没有其他因素干扰，当你打开路由的history模式之后，开发的时候一切正常</p>
<p><img src="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/28200b7f45b8aac0897f62124c41eec1?raw=true" alt="打包之前的路由"></p>
<h4 id="打包之后的样子："><a href="#打包之后的样子：" class="headerlink" title="打包之后的样子："></a>打包之后的样子：</h4><p><img src="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/f9c56757612f1dd5703fbf0fa09fb155?raw=true" alt="打包之后路径也是对的，但是页面一片空白"></p>
<h4 id="解决方式："><a href="#解决方式：" class="headerlink" title="解决方式："></a>解决方式：</h4><pre><code>// mode: &apos;history&apos;,//将这个模式关闭就好
</code></pre><p>这里并不是说不能打开这个模式，这个模式需要后端设置的配合，详情可以看：<a href="https://router.vuejs.org/zh-cn/essentials/history-mode.html" target="_blank" rel="noopener">路由文档</a></p>
<hr>
<h3 id="Gzip-文件压缩"><a href="#Gzip-文件压缩" class="headerlink" title="Gzip 文件压缩"></a>Gzip 文件压缩</h3><p>顺带分享一个很6的优化打包的方法，用起来也简单的很，只要下载一个插件，然后打开一个设置就好了。</p>
<h4 id="设置方法："><a href="#设置方法：" class="headerlink" title="设置方法："></a>设置方法：</h4><p><img src="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/1f95faabfb7463e1dce708f046960398?raw=true" alt=""></p>
<p>这里其实是webpack自带的一个优化打包的方法，打开这个配置后如果没有下载那个插件，会提示你下载，下载就好了。</p>
<p>然后在打包的时候，每个js和css文件会压缩一个gz后缀的文件夹，浏览器如果支持g-zip 会自动查找有没有gz文件 找到了就加载gz然后本地解压 执行。</p>
<p>打开这个配置会之后对整体的打包体积也就是dist文件夹并没有太大的变化。下图来看看他的压缩率以及对加载的提升，可以说是非常大且明显的，大家可以自己试一下就知道多好用了。</p>
<p><img src="https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/7fd308bb2a27aba49009455266da73d3?raw=true" alt=""></p>
<h2 id="后话"><a href="#后话" class="headerlink" title="后话"></a>后话</h2><p>之前自己打包的时候连着踩了不少坑，可能是互相关联的，有时候你并不是错了一个地方，要想想自己其他地方是不是也是错的。上述的内容，算是自己踩坑的一些经验，希望可以帮到大家。</p>
<p><strong>最后</strong>：如需转载，请放上原文链接并署名。码字不易，<strong>感谢</strong>支持！本人写文章本着交流记录的心态，写的不好之处，不撕逼，但是欢迎指点。然后就是希望看完的朋友点个<strong>喜欢</strong>，也可以<strong>关注</strong>一下我。<br><strong><a href="https://juejin.im/user/58714f0eb123db4a2eb95372" target="_blank" rel="noopener">掘金个人主页</a> </strong></p>
<p>以上2017.10.10</p>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>听说，打赏我的人最后都找到了真爱。</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/pay/weixin.jpg" alt="OBKoro1 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/pay/ali.jpg" alt="OBKoro1 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/build空白页/" rel="tag"><i class="fa fa-tag"></i> build空白页</a>
          
            <a href="/tags/gzip文件压缩/" rel="tag"><i class="fa fa-tag"></i> gzip文件压缩</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/10/11/vue-cli-自定义路径别名-assets和static文件夹的区别-save-dev和-save的区别/" rel="next" title="vue-cli 自定义路径别名 assets和static文件夹的区别 --save-dev和--save的区别">
                <i class="fa fa-chevron-left"></i> vue-cli 自定义路径别名 assets和static文件夹的区别 --save-dev和--save的区别
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/10/15/js-计算两个时间的时间差/" rel="prev" title="js 计算两个时间的时间差">
                js 计算两个时间的时间差 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          
            <img class="site-author-image" itemprop="image"
              src="/uploads/hand1.jpg"
              alt="OBKoro1" />
          
            <p class="site-author-name" itemprop="name">OBKoro1</p>
            <p class="site-description motion-element" itemprop="description">种一棵树最好的时间是十年前,其次是现在</p>
        </div>

        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
            
              <a href="/archives">
            
                <span class="site-state-item-count">105</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">20</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">74</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/OBKoro1" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>GitHub</a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://juejin.im/user/58714f0eb123db4a2eb95372" target="_blank" title="掘金">
                  
                    <i class="fa fa-fw fa-globe"></i>掘金</a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://obkoro1.com/web_accumulate/" target="_blank" title="前端积累">
                  
                    <i class="fa fa-fw fa-globe"></i>前端积累</a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://segmentfault.com/u/obkoro1/articles" target="_blank" title="segmentfault">
                  
                    <i class="fa fa-fw fa-globe"></i>segmentfault</a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#写在前面："><span class="nav-number">1.</span> <span class="nav-text">写在前面：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#初始化一个项目："><span class="nav-number">2.</span> <span class="nav-text">初始化一个项目：</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#命令行："><span class="nav-number">2.1.</span> <span class="nav-text">命令行：</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#开始打包踩坑"><span class="nav-number">3.</span> <span class="nav-text">开始打包踩坑</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#命令行：-1"><span class="nav-number">3.1.</span> <span class="nav-text">命令行：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#打包出来的文件"><span class="nav-number">3.2.</span> <span class="nav-text">打包出来的文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#第一个坑：文件引用路径"><span class="nav-number">3.3.</span> <span class="nav-text">第一个坑：文件引用路径</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#爬坑："><span class="nav-number">3.4.</span> <span class="nav-text">爬坑：</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-更改assetsPublicPath属性："><span class="nav-number">3.4.1.</span> <span class="nav-text">1.更改assetsPublicPath属性：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-改好设置之后，重新打包。"><span class="nav-number">3.4.2.</span> <span class="nav-text">2.改好设置之后，重新打包。</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#错误原因："><span class="nav-number">3.4.3.</span> <span class="nav-text">错误原因：</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#第二个坑：路由history模式。"><span class="nav-number">3.5.</span> <span class="nav-text">第二个坑：路由history模式。</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#打包之前的样子："><span class="nav-number">3.5.1.</span> <span class="nav-text">打包之前的样子：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#打包之后的样子："><span class="nav-number">3.5.2.</span> <span class="nav-text">打包之后的样子：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#解决方式："><span class="nav-number">3.5.3.</span> <span class="nav-text">解决方式：</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Gzip-文件压缩"><span class="nav-number">3.6.</span> <span class="nav-text">Gzip 文件压缩</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#设置方法："><span class="nav-number">3.6.1.</span> <span class="nav-text">设置方法：</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#后话"><span class="nav-number">4.</span> <span class="nav-text">后话</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2017 &mdash; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">OBKoro1</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">
      156.0k
    </span>
  
</div>




<div>
<script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<span class="site-uv"><i class="fa fa-user"></i> 访问用户： <span class="busuanzi-value" id="busuanzi_value_site_uv">21621</span> 人 </span>
<span class="site-pv"><i class="fa fa-eye"></i> 访问次数： <span class="busuanzi-value" id="busuanzi_value_site_pv">68503</span> 次</span>

</div>



        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>

  
  <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.2"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.2"></script>



  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.2"></script>


  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.2"></script>



  


  




	





  





  








  



  





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("9ANFp60h6oVyxIPGlau3NOA4-gzGzoHsz", "tMdNuKMbFtN4QsekeNVu83TV");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  

  

  

</body>
</html>

